package com.wave.wavesystem.business.controller;

import com.mybatisflex.core.paginate.Page;
import com.wave.wavesystem.business.pojo.dto.dept.DeptRoleQueryRequest;
import wave.common.pojo.enums.RStatusEnum;
 import wave.common.pojo.entity.Result;
import com.wave.wavesystem.common.util.Condition;
import com.wave.wavesystem.common.util.Func;
import com.wave.wavesystem.business.pojo.entity.DeptRoleEntity;
import com.wave.wavesystem.business.service.DeptRoleService;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;

import java.util.List;

/**
* @author 夕下风波
* @date 2025-02-13
* @description 部门-角色关联表 访问层
*/
@RestController
@RequestMapping("/deptRole")
public class DeptRoleController {

    @Resource
    private DeptRoleService deptRoleService;

    /**
    * 新增
    *
    * @param deptRole 新增实体
    */
    @Operation(summary = "保存")
    @PostMapping("/save")
    public Result<DeptRoleEntity> save(@RequestBody DeptRoleEntity deptRole) {
        deptRoleService.save(deptRole);
        return Result.data(deptRole);
    }

    /**
    * 删除/批量删除
    *
    * @param ids id集合
    */
    @Operation(summary = "删除")
    @PostMapping("/remove")
    public Result<Boolean> remove(String ids) {
        List<String> idList = Func.strToStringList(ids);
        return Result.status(deptRoleService.removeByIds(idList),RStatusEnum.SUCCESS);
    }

    /**
    * 更新
    *
    * @param deptRole 更新内容
     */
     @Operation(summary = "更新")
     @PostMapping("/update")
     public Result<DeptRoleEntity> update(@RequestBody DeptRoleEntity deptRole) {
         deptRoleService.updateById(deptRole);
         return Result.data(deptRoleService.getById(deptRole.getId()), RStatusEnum.SUCCESS);
     }

     /**
     * 详情查询
     *
     * @param deptRole 查询条件
     */
     @Operation(summary = "详情")
     @GetMapping("/detail")
     public Result<DeptRoleEntity> detail(DeptRoleQueryRequest deptRole) {
          return Result.data(deptRoleService.getById(deptRole.getId()));
     }

      /**
       * 列表查询
       *
       *@param deptRoleQueryRequest 查询条件
       */
       @Operation(summary = "列表")
       @GetMapping("/list")
       public Result<List<DeptRoleEntity>> list(DeptRoleQueryRequest deptRoleQueryRequest) {
                        DeptRoleEntity deptRole= new DeptRoleEntity();
           Func.beanCopy(deptRoleQueryRequest, deptRole);
            return Result.data(deptRoleService.list(Condition.getQueryWrapper(deptRole)));
       }

       /**
       * 条件分页查询
       *
       * @param deptRoleQueryRequest 查询条件
       */
       @Operation(summary = "分页")
       @GetMapping("/page")
       public Result<Page<DeptRoleEntity>> page(DeptRoleQueryRequest deptRoleQueryRequest) {
            DeptRoleEntity deptRole = new DeptRoleEntity();
            Func.beanCopy(deptRoleQueryRequest, deptRole);
             return Result.data(deptRoleService.page(new Page<>(deptRoleQueryRequest.getPageNum(), deptRoleQueryRequest.getPageSize()),
             Condition.getQueryWrapper(deptRole)));
       }

}